<template>
  <div class="page">
    <div class="headerTitle">
      <router-link to="/" class="iconfont icon-back_light"></router-link>
      <span>会员全网VIP免费看</span>
    </div>
    <div class="indexHeader">
      <div class="swiper-container">
        <div class="swiper-wrapper">
          <div class="swiper-slide">
            <img src="/static/img/titleimg.jpg" alt="">
          </div>
          <div class="swiper-slide">
            <img src="/static/img/titleimg1.jpg" alt="">
          </div>
          <div class="swiper-slide">
            <img src="/static/img/titleimg2.jpg" alt="">
          </div>
        </div>
        <div class="swiper-pagination"></div>
      </div>
    </div>
    <div class="fromBox">
      <input type="text" v-model="username" placeholder="用户名">
      <input type="password" v-model="password" placeholder="密码">
      <a @click.stop="gotoVip">登录</a>
      <span @click.stop="gotoReg">没有账号？去注册</span>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import axios from "axios";
  import router from "../router/index";
  import swiper from "../../static/javascript/swiper-3.4.2.min.js";
  export default {
    data() {
      return {
        username: "",
        password: ""
      };
    },
    methods: {
      gotoReg: function() {
        router.push({
          path: "/reg"
        });
      },
      gotoVip: function() {
        let that = this;
                  // router.push({
                  //   path: "/vipHome"
                  // });
        if (that.username != "" && that.password != "") {
          $.ajax({
            url: "http://vapi.dicbs.cn/user/login",
            type: "post",
            data: {
              username: that.username,
              password: that.password
            },
            success: function(data) {
         console.log(data)
              let obj = data.data;
              if (data.code == "200") {
                window.localStorage.removeItem("pass")
                 window.localStorage.setItem("pass",that.password)
                window.localStorage.removeItem("Uname");
                window.localStorage.setItem("Uname", obj.username);
                window.localStorage.removeItem("startTime");
                window.localStorage.setItem("startTime", data.data.endDate);
                window.localStorage.removeItem("status");
                window.localStorage.setItem("status", obj.status);
       
                  router.push({
                    path: "/vipHome"
                  });
           
              }
              if (data.code == "4002") {
                alert(data.memages + "请联系客服!");
                router.push({path:'/kf'})
              } else {
                alert(data.memages);
                that.username = "";
                that.password = "";
              }
            }
          });
        } else {
          alert("请输入完整信息");
        }
      }
    },
    mounted() {
      let swiper = new Swiper(".swiper-container", {
        pagination: ".swiper-pagination",
        paginationClickable: true
      });
    }
  };
</script>

<style>

</style>
